import javax.servlet.ServletException;
import javax.servlet.annotation.MultipartConfig;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.Part;
import java.io.IOException;

@MultipartConfig
@WebServlet("/upload")  // 貌似开头不能大写
public class UploadServlet extends HttpServlet {
    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        // core method just use one of the Servlet.http 的 Part 对象
        // req.getPart 请求获取前端的文件

        Part part = req.getPart("Myfile");
        System.out.println(part.getSubmittedFileName());  // 上传文件的名字
        System.out.println(part.getSize());  // 上传的文件大小
        System.out.println(part.getContentType()); //上传的文件类型
        // 上传的位置是一张图片
        part.write("d:/666/Myfile.png");
        resp.getWriter().write("unload ok");

    }
}
